<template>
	<view class="pop-box-container">
		<view class="popup-content">
			<view class="popup-content-title">
				<!-- <view v-if="title != ''" class="popup-content-title-tt">您还没有登陆呦~</view> -->
				<view v-if="tip != ''" class="popup-content-title-tip">注：{{tip}}</view>
			</view>
			<slot name="body">
				<view class="popup-content-body">
					<view class="popup-content-body-item">
						<view class="popup-content-body-item-child font-24 text-center">
							您还没有登陆呦~
						</view>
						<!-- <view v-if="item.child && item.child.length > 0" class="popup-content-body-item-child font-28">
							<view v-for="(child,i) in item.child" :key="i">{{child}}</view>
						</view>
						<view v-if="item.child2 && item.child2.length > 0"
							class="popup-content-body-item-child font-28">
							<view v-for="(child,i2) in item.child2" :key="i2">{{child}}</view>
						</view>
						<view v-if="item.child3 && item.child3.length > 0"
							class="popup-content-body-item-child font-28">
							<view v-for="(child,i3) in item.child3" :key="i3">{{child}}</view>
						</view> -->
					</view>
					<view class="popup-content-body-item">
						<view class="popup-content-body-item-child font-24 text-center">
							快去登陆查看完整内容吧
						</view>

					</view>
				</view>
			</slot>
			<view class="popup-content-footer">
				<view class="popup-content-footer-item popup-content-footer-cance" @tap.stop="cance()">
					取消
				</view>
				<view class="popup-content-footer-item popup-content-footer-confirm" @tap.stop="confirm()">登陆
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "t-pop-login",
		data() {
			return {
				requestIng: false
			};
		},
		props: {
			data: {
				type: Object,
				default: null
			},
			title: {
				type: String,
				default: ''
			},
			tip: {
				type: String,
				default: ''
			},
			body: {
				type: Array,
				default: () => {
					return [
						/* {
							title: 'title',
							child: ['child', 'child']
						},
						{
							title: 'title',
							child: ['child', 'child']
						}, */
					]
				}
			},
			showCance: {
				type: Boolean,
				default: true
			},
			showConfirm: {
				type: Boolean,
				default: true
			},
			canceText: {
				type: String,
				default: '取消'
			},
			confirmText: {
				type: String,
				default: '确认发布'
			},
		},
		computed: {
			/* showAuth: {
				get() {
					let auth = uni.getStorageSync('authUserInfo');
					return !auth;
				},
				set(value) {
					// value ? uni.hideTabBar() : uni.showTabBar();
				}
			} */
		},
		mounted() {
			// let auth = uni.getStorageSync('authUserInfo');
			// if(!auth) this.$refs.login.open('center');
		},
		methods: {
			/* confirm() {
				console.log('confirm')
				this.$emit('confirm')
			}, */
			confirm() {
				this.$emit('confirm');
				let that = this;
				if (that.requestIng) return;
				that.requestIng = true;
				if (uni.getUserProfile) {
					return new Promise((resolve, reject) => {
						uni.getUserProfile({ // 必须手动确认触发
							desc: "登陆", // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
							success: res => {
								uni.hideLoading();
								console.log('更新会员资料返回值', res)
								if (res.errMsg === "getUserProfile:ok") {
									that.$util.loading('登陆中');
									that.$http('user.updateUserInfo', {
											encryptedData: res.encryptedData,
											iv: res.iv,
											signature: res.signature,
											rawData: res?.rawData,
											nickName: res?.userInfo?.nickName,
											avatarUrl: res?.userInfo?.avatarUrl,
										}).then(res => {
											console.log('更新返回值', res)
											that.requestIng = false
											uni.hideLoading()
											let data = res.data
											if (res.code == 1) {
												that.$util.msg('登陆成功');
												that.$store.dispatch('getUserInfo');
												uni.setStorageSync('authUserInfo', true)
												// resolve(true);
											} else {
												that.$util.msg(res.msg || '更新失败');
												// resolve(false);
											}
										})
										.catch(err => {
											that.requestIng = false
											uni.hideLoading()
											that.$util.msg('网络异常');
											// resolve(false);
										})
								}
							},
							fail: err => {
								that.requestIng = false
								console.log('getUserProfile-fail')
								uni.setStorageSync('authUserInfo', false)
								uni.hideLoading();
							}
						});
					});
				}
			},
			cance() {
				console.log('cance')
				this.$emit('cance')
			}
		}
	}
</script>

<style lang="scss">
	.pop-flex-s {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.pop-flex-c {
		display: flex;
		flex-direction: column;
		justify-content: center;
	}

	/* .uni-popup__wrapper {
		border-radius: 10px;
	} */


	.popup-content {
		@extend .pop-flex-c;
		width: 90vw;
		border-radius: 50px;

		// padding: 20rpx 2vw;
		.popup-content-title,
		.popup-content-body {
			padding: 0 30rpx;
		}

		.popup-content-title {
			@extend .pop-flex-c;
			margin: 20rpx 0;

			.popup-content-title-tt {
				display: flex;
				justify-content: center;
				font-size: 40rpx;
				font-weight: 700;
				color: #222;
			}

			.popup-content-title-tip {
				color: #ff9000;
				font-size: 20rpx;
				margin-top: 20rpx;
			}
		}

		.popup-content-body {
			@extend .pop-flex-c;
			margin: 20rpx 0 30rpx;

			.popup-content-body-item {
				@extend .pop-flex-c;

				.popup-content-body-item-child {
					@extend .pop-flex-s;
					height: 60rpx;
				}

				.text-center {
					justify-content: center;
					font-size: 28rpx;
				}
			}
		}

		.popup-content-footer {
			@extend .pop-flex-s;
			border-top: 1px solid #ff9000;
			height: 80rpx;

			.popup-content-footer-item {
				@extend .pop-flex-s;
				justify-content: center;
				flex: 1;
				height: 100%;
			}

			.popup-content-footer-cance {}

			.popup-content-footer-confirm {
				background: #ff9000;
				color: #fff;
				border-radius: 0 0 10px 0;
			}
		}
	}

	.font-24 {
		font-size: 24rpx;
		color: #666;
	}

	.font-28 {
		font-size: 28rpx;
		color: #222;
		font-weight: 600;
	}
</style>
